<template>
  <div class="pagination-wrapper">
    <el-pagination
        v-show="total > 0"
        v-model:current-page="currentPage"
        v-model:page-size="pageSize"
        :total="total"
        :small="false"
        :disabled="false"
        :page-sizes="[10, 20, 50, 100]"
        :background="false"
        layout="total, prev, pager, next, sizes, jumper"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
    />
  </div>
</template>

<script setup>
import { computed } from 'vue'

const props = defineProps({
  pageInfo: {
    type: Object,
    required: true
  },
  total: {
    type: Number,
    required: true
  }
})

const emit = defineEmits(['update:pageInfo'])

const currentPage = computed({
  get() {
    return props.pageInfo.request.pageDomain.pageNum
  },
  set(val) {
    props.pageInfo.request.pageDomain.pageNum = val
  }
})

const pageSize = computed({
  get() {
    return props.pageInfo.request.pageDomain.pageSize
  },
  set(val) {
    props.pageInfo.request.pageDomain.pageSize = val
  }
})

const handleSizeChange = (val) => {
  pageSize.value = val
  props.pageInfo.paging()
}

const handleCurrentChange = (val) => {
  currentPage.value = val
  props.pageInfo.paging()
}
</script>

<style scoped lang="scss">
.pagination-wrapper {
  padding: 0 20px;

  :deep(.el-pagination) {
    float: right;
    margin-top: 20px;

    .el-input {
      height: 26px;
    }
  }
}
</style>
